﻿#if WINDOWS_PHONE
using System.Windows;
using Microsoft.Phone.Controls;
#elif NETFX_CORE
using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
#endif
#if WINDOWS_PHONE || NETFX_CORE
namespace Nx.Commands
{
    public class ControlTapCommandBehavior : CommandBehaviorBase<UIElement>
    {
        public ControlTapCommandBehavior(UIElement tapableObject)
            : base(tapableObject)
        {
            if (tapableObject == null)
            {
                throw new System.ArgumentNullException("tapableObject");
            }
#if WINDOWS_PHONE            
            var listener = GestureService.GetGestureListener(tapableObject);
            listener.Tap += OnTap;
#elif NETFX_CORE
            tapableObject.Tapped += OnTap;
#endif
        }



#if WINDOWS_PHONE
        private void OnTap(object sender, GestureEventArgs e)
        {
            ExecuteCommand();
        }  
#elif NETFX_CORE
        private void OnTap(object sender, TappedRoutedEventArgs e)
        {
            ExecuteCommand();
        }
#endif
    }
}
#endif